<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/includes.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Q n A 쓰기</title>

<%
	

%>
<script type="text/javascript">
function beforeWrite(){
	var title = $("#TITLE").val();
	var content = $("#CONTENT").val();
	
	if(title ==""){
		alert("제목을 입력해 주세요.");
		return;
	}
	else if(content == ""){
		alert("내용을 입력해 주세요.");
		return;
	}
	writeQna();
}

function writeQna(){
	$("#insertForm").submit(function(){
		var insertForm = $("#insertForm").serialize();
		
		$.ajax({	//ajax : dataType을 String으로 값 반환, json : json객체로 반환
			type : "POST",
			url : "insert.qna" ,
			data : insertForm 
// 			,
// 			success : function(result){
// 				if(result > 0){
// 					alert('글이 등록되었습니다.');
// 				}
// 				else{
// 					alert('글이 등록되지 않았습니다.');
// 				}
// 			}
		});
		return false;
	});
	$("#insertForm").submit();
	
}
</script>
</head>
<body>
<form action="" name="insertForm" id="insertForm" method="post">
<input type="hidden" name="cmd" id = "cmd" value="insert"/>
<input type="hidden" name="SSO_ID" id = "SSO_ID" value="<%=SSO_ID %>"/>

<div align="center" style="width:  1000px; height: 600px;">
		<div>	
			<h1>Q n A 쓰기</h1>
		</div>
	
	<div id="QnaContent" class="QnaContent">
		<table style="border: 1;">
			<tr>
				<td><div>글번호</div></td>
				<td id="QNA_SEQ"><div></div></td>
				<td><div>작성자</div></td>
				<td><div><%= SSO_ID %></div></td>
			</tr>
			<tr>
				<td><div>제목</div></td>
				<td><input type="text" name="TITLE" id="TITLE"/></td>
			</tr>
			<tr>
				<th>내용</th>
				<td>
					<textarea rows="10" cols="20" name="CONTENT" id="CONTENT" ></textarea>
				</td>
			</tr>
			<tr>
				<td><input type="button" value="확인" onclick="beforeWrite();"/></td>
				<td><input type="reset" value="취소" /></td>
			</tr>
		</table>
	</div>
</div>	
</form>
</body>
</html>